package com.gsk.test123.service.impl;

import com.baomidou.mybatisplus.plugins.Page;
import com.gsk.test123.config.DataSourceType;
import com.gsk.test123.config.JdbcContextHolder;
import com.gsk.test123.entity.Users;
import com.gsk.test123.mapper.UsersMapper;
import com.gsk.test123.service.UsersService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author jrw
 * @since 2018-06-21
 */
@Service
public class UsersServiceImpl extends ServiceImpl<UsersMapper, Users> implements UsersService {

    @Autowired
    UsersMapper usersMapper;

    @Override
    public Users getusers1() {
        JdbcContextHolder.putDataSource(DataSourceType.Master.getName());
//        JdbcContextHolder.putDataSource(DataSourceType.Slave.getName());
        Users users = new Users();
        users.setId("4ac02324-1d09-46db-a55f-5265c83115e6");
        return usersMapper.selectById(users.getId());
    }

    @Override
    public void insetUsers2() {
        JdbcContextHolder.putDataSource(DataSourceType.Master.getName());
        Users users = new Users();
        users.setId("4ac02324-1d09-46db-a55f-5265c83115e6");
        Users users1 =  usersMapper.selectById(users.getId());
        JdbcContextHolder.putDataSource(DataSourceType.Slave.getName());
        usersMapper.insert(users1);
    }
}
